<?php #//v.3.3.0
#///////////////////////////////////////////////////////
#//  COPYRIGHT 2004 Phpauction.org ALL RIGHTS RESERVED//
#///////////////////////////////////////////////////////
require('../includes/config.inc.php');
include "loggedin.inc.php";
//-- Set offset and limit for pagination
$limit = 30;
if(!$_GET[offset]) {
  $offset = 0;
} else {
  $offset = $_GET[offset];
}
$PAGES = ceil($TOTALUSERS / $limit);
#// Set return script name
$_SESSION['RETURN_LIST'] = 'listclosedauctions.php';
$_SESSION['RETURN_LIST_OFFSET'] = intval($_GET['offset']);


?>
<HTML>
<HEAD>
<link rel='stylesheet' type='text/css' href='style.css' />
<link href="css/main.css" rel="stylesheet" type="text/css">
</HEAD>
<bodyleftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0" class="titulo">
        <tr> 
          <td class="icono"><img src="images/auction_icon2.gif" width="31" height="25" ></td>
          <td  class="breadcrumbs"><p><span><?=$MSG_239?></span>&nbsp;&gt;&gt;&nbsp;<?=$MSG_5226?></p></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td align="center" valign="middle">&nbsp;</td>
  </tr>
    <tr> 
    <td align="center" valign="middle">
<TABLE WIDTH="95%" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="CENTER" class="base" style="border:1px solid #ccc;">
<TR>
  <TD ALIGN=CENTER class=title><p><? print $MSG_5226; ?></p></TD>
</TR>
<TR>
  <TD><TABLE WIDTH=100% CELPADDING=0 CELLSPACING=0 BORDER=0 ALIGN="CENTER" CELLPADDING="0">
      <?
      $query = "select count(id) as auctions from PHPAUCTIONXL_auctions WHERE closed<>'0' AND suspended='0'";
      $result = mysql_query($query);
      if(!$result){
      	print "$ERR_001<BR>$query<BR>".mysql_error();
      	exit;
      }
      $num_auctions = mysql_result($result,0,"auctions");
      print "<TR BGCOLOR=#FFFFFF><TD COLSPAN=7><B>
				$num_auctions $MSG_311</B> 
				</TD></TR>";
	?>
      <TR BGCOLOR="#FFFFC0">
        <!-- <TD ALIGN=CENTER> <B> <? print $MSG_312; ?> </B>  </TD>
        <TD ALIGN=CENTER> <B> <? print $MSG_313; ?> </B>  </TD>
        <TD ALIGN=CENTER> <B> <? print $MSG_314; ?> </B>  </TD>
        
        <TD ALIGN=LEFT> <B> <? print $MSG_316; ?> </B>  </TD>
        <TD ALIGN=LEFT> <B> <? print $MSG_317; ?> </B>  </TD>
        <TD ALIGN=LEFT> <B> <? print $MSG_297; ?> </B>  </TD> -->
      </tr>
        <?
					$query = "SELECT DISTINCT(a.id), a.refund, a.reserve_price, a.current_bid, a.current_high_bidder, a.closed, u.nick, a.title, a.starts, a.description, a.paid, c.cat_name, a.suspended
				  FROM PHPAUCTIONXL_auctions a, PHPAUCTIONXL_users u, PHPAUCTIONXL_categories c
				  where u.id = a.user and c.cat_id = a.category and a.closed<>'0' AND a.suspended='0'
				  ORDER BY a.id limit $offset, $limit";
					$result = mysql_query($query);
					if(!$result){
						print "Database access error: abnormal termination<BR>$query<BR>".mysql_error();
						exit;
					}
					$num_auction = mysql_num_rows($result);
					$i = 0;
					$bgcolor = "#FFFFFF";
					while($i < $num_auction) {
						if($bgcolor == "#FFFFFF"){
							$bgcolor = "#EEEEEE";
						}else{
							$bgcolor = "#FFFFFF";
						}
						$id = mysql_result($result,$i,"id");
						
						#// ============================== Added on May 26, 2003 ========================================
						/*$query = "SELECT id,winner FROM PHPAUCTIONXL_winners WHERE auction='$id'";
						$res_w = @mysql_query($query);
						if(!$res_w) {
							print "$query<BR>".mysql_error();
							exit;
						} elseif(@mysql_num_rows($res_w) > 0) {
							$HASWINNERS = TRUE;
							$userid_winner = mysql_result($res_w,0,"winner")  ;
						} else {
							$HASWINNERS = FALSE;
						}    */
						#// =============================================================================================
						
            $current_high_bidder = mysql_result($result,$i,"current_high_bidder");

						
						
						
						$title = stripslashes(mysql_result($result,$i,"title"));
						$nick = mysql_result($result,$i,"nick");
						$tmp_date = mysql_result($result,$i,"starts");
						//$duration = mysql_result($result,$i,"duration");
						$category = mysql_result($result,$i,"cat_name");
						$description = strip_tags(stripslashes(mysql_result($result,$i,"description")));
						$suspended = mysql_result($result,$i,"suspended");
						$refund = mysql_result($result,$i,"refund");
						$current_bid = mysql_result($result,$i,"current_bid");
						$paid = mysql_result($result,$i,"paid");
						$reserve_price = mysql_result($result,$i,"reserve_price");
						
						$day = substr($tmp_date,6,2);
						$month = substr($tmp_date,4,2);
						$year = substr($tmp_date,0,4);
						$date = "$day/$month/$year";
						        $HASWINNERS = FALSE;
						   if ( $current_bid > 0 ) {
               if ( $current_bid > $reserve_price ) {
                 $HASWINNERS = TRUE;
               
               }
               }
						
						    
						print "<TR BGCOLOR=$bgcolor>
					<TD>";
						if($suspended == 1) {
							print "<FONT COLOR=red><B>$title</B>";
						} else {
							print "id#: $id - <A href=\"../item.php?id=".$id."\" >".$title."</a>";
						}
						print "
						</TD>
						<TD>";
							
              if($HASWINNERS) {
                          $query222 = "SELECT * FROM PHPAUCTIONXL_users WHERE nick='$current_high_bidder'";
						$res_w = @mysql_query($query222);
						$userid_winner = mysql_result($res_w,0,"id"); 
							print "<A HREF=\"edituser.php?userid=$userid_winner\" class=\"nounderlined\">Winner's Info</A>";
						
              if( $paid == 1 ) {
							print " <font color=green >PAID</A>";
						}
						
						      if( $paid != 1 ) {
							print " <font color=red >UNPAID</A>";
						}
            }
						
						     
						
						     					print "
						</TD>
						<TD>
						<A href=\"../relistauction.php?id=".$id."\" >$MSG_AJAX_ADMIN_LIST_CLOSED_RELIST_ITEM</a>
												</TD>
						<TD ALIGN=LEFT>
						<A HREF=\"../complete_history.php?id=$id\" class=\"nounderlined\">Bid History</A><BR>
						</TD>
						<TD><A HREF=\"deleteauction.php?id=$id&offset=$offset\" class=\"nounderlined\">$MSG_299</A><BR>
						<!-- <A HREF=\"excludeauction.php?id=$id&offset=$offset\" class=\"nounderlined\"> -->";
								if($suspended == 0) {
							//print $MSG_300;
						} else {
							//print $MSG_310;
						}
						//print "</A><BR>";
						
						  if($refund == 0 ) {
          
          print "</TD>
						<TD><A HREF=\"refund_bids_for_an_entire_auction.php?id=$id\" class=\"nounderlined\">$MSG_AJAX_ADMIN_AUCTION_REFUND_BIDS_FOR_AUCTION2</A><BR>";
						               }
						                if($refund == 1 ) {
          
          print "<font color=red >$MSG_AJAX_ADMIN_AUCTION_REFUND_BIDS_FOR_AUCTION3</font><BR>";
						               }
               /*            	
						if($HASWINNERS) {
							print "<A HREF=\"viewwinners.php?id=$id&offset=$offset\" class=\"nounderlined\">$MSG__0163</A>";
						}   */
						print "
						</TD>
						<TR>";
						$i++;
					}
					?>
					</TABLE>
					<?
					//-- Build navigation line
					print "<TABLE WIDTH=100% BORDER=0 CELLPADDING=4 CELLSPACING=0 ALIGN=CENTER>
			   <TR ALIGN=CENTER BGCOLOR=#FFFFFF>
			   <TD COLSPAN=2>";
					print "<SPAN CLASS=\"navigation\">";
					$num_pages = ceil($num_auctions / $limit);
					$i = 0;
					while($i < $num_pages ){
						$of = ($i * $limit);
						if($of != $offset){
							print "<A HREF=\"listclosedauctions.php?offset=$of\" CLASS=\"navigation\">".($i + 1)."</A>";
							if($i != $num_pages) print " | ";
						}else{
							print $i + 1;
							if($i != $num_pages) print " | ";
						}
						$i++;
					}
					print "</SPAN></TR></TD></table>";
					
	  ?>
    </td></tr>
	</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>